use common::error::MyError;
use common::page::{BasePage, PageResult};

/// 抽象数据库操作层
/// Unlike [`ID`] ID 实体模型id类型
/// Unlike [`ENTITY`] 实体模型
/// Unlike [`PAGE`] 分页参数
/// Unlike [`CREATE`] 添加数据的入参对象
/// Unlike [`UPDATE`] UPDATE 更新数据的入参对象
#[allow(async_fn_in_trait)]
pub trait BaseManager<ID, ENTITY, PAGE, CREATE, UPDATE>
where
    PAGE: BasePage,
{
    async fn list() -> Result<Vec<ENTITY>, MyError>;

    async fn page(page: PAGE) -> Result<PageResult<ENTITY>, MyError>;

    async fn info(id: ID) -> Result<Option<ENTITY>, MyError>;

    async fn add(form: CREATE) -> Result<ID, MyError>;

    async fn update(form: UPDATE) -> Result<ID, MyError>;

    async fn delete(id: ID) -> Result<bool, MyError>;
}
